<?php
namespace app\center\controller;
use app\center\logic\HistoryMatterUserLogic;

/**
 * 历史事项个人api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/09
 * Time: 15:12
 */
class HistoryMatterUser extends Base {

    public function __construct(){
        parent::__construct();
        $this->hmu_logic = new HistoryMatterUserLogic();
    }

    /**
     * 获取历史事项个人
     * @return \think\response\Json
     */
    public function ajax_get_hmu(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->hmu_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];

        $maps = $this->hmu_logic->get_search_hmu_maps($u_detail['openid'],$params['from_openid'],$params['source'],$params['confirm_status'],$params['matter_status'],$params['start_time']);
        $limit = ($params['page'] - 1) * $params['rows'];

        $list = model('matter')->get_list($maps,'id,from_openid,source,name,out_time,is_read,c_time','id desc','',$limit,$params['rows']);
        foreach($list as $k => $v){
            //查找用户
            $u_maps = [];
            $u_maps[] = ['openid','=',$v['from_openid']];
            $u_detail = model('user')->get_detail($u_maps,'id,username');

            $content = '发起人：' . $u_detail['username'];
            $content = ($v['out_time'] != '0000-00-00 00:00:00') ? $content . '，截止时间：' . $v['out_time'] : $content;

            $list[$k]['content'] = $content;
        }

        $total_num = model('matter')->get_count($maps,'id');

        $data['list'] = $list;
        $data['total_num'] = $total_num;
        $data['page'] = $params['page'];
        return json($this->hmu_logic->get_response(1,'OK',$data));
    }
}
